package com.ten.shou.service.impl;




import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ten.common.core.entity.HeadNav;
import com.ten.common.core.vo.Result;
import com.ten.shou.dao.HeadDao;
import com.ten.shou.service.HeadService;
import com.ten.shou.vo.HeadVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：杨（1964958771@qq.com）
 * @date ：Created in 2022/12/5 20:35
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class HeadServiceImpl implements HeadService {
    @Resource
    private HeadDao headDao;
    @Override
    public Result<IPage<HeadNav>> getAllHeadNav(Integer current, Integer pageSize, HeadVo headVo) {
        IPage<HeadNav> page=new Page<>(current,pageSize);
        QueryWrapper<HeadNav> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(headVo.getHeadName())){
            wrapper.like("head_name",headVo.getHeadName());
        }
        if (StringUtils.hasText(headVo.getIsDiable())){
            wrapper.eq("is_diable",headVo.getIsDiable());
        }
        IPage<HeadNav> headNavIPage = headDao.selectPage(page, wrapper);
        return new Result<>(2000,"查询成功",headNavIPage);
    }

    @Override
    public Result<HeadNav> insertAll(HeadNav headNav) {
        headNav.setIsDelete("0");
        headDao.insert(headNav);
        return new Result(2000,"添加成功");
    }

    @Override
    public Result<HeadNav> deleteById(HeadVo headVo) {
        headDao.deleteById(headVo.getHeadId());
        return new Result<>(2000,"删除成功");
    }

    @Override
    public Result<HeadNav> updateStatusHead(String headId ,String isDiable) {
        UpdateWrapper<HeadNav> wrapper=new UpdateWrapper<>();
        if (StringUtils.hasText(headId)){
            wrapper.eq("head_id",headId);
        }
        if (StringUtils.hasText(isDiable)){
            wrapper.set("is_diable",isDiable);
        }
        headDao.update(null,wrapper);
        return new Result<>(2000,"修改成功");
    }

    @Override
    public Result<HeadNav> updateOperate(HeadNav headNav) {
        headDao.updateById(headNav);
        return new Result(2000,"修改成功");
    }

    /**
     * 客户端
     * @return
     */
    @Override
    public Result getAllHead() {
        QueryWrapper<HeadNav> wrapper=new QueryWrapper<>();
        wrapper.eq("is_diable","0");
        List<HeadNav> headNavs = headDao.selectList(wrapper);
        return new Result(2000,"查询成功",headNavs);
    }


}
